# -*- coding: utf-8 -*-
"""
 ----------------------------------------
|File Name:     sm2
|Author:        WYT
|date:          2021/7/2
 ----------------------------------------
|  Change Activity:
|                   2021/7/2:
-----------------------------------------
"""

from util.encryption_password.ecdsa_modified import KjurCryptoEcdsa


class sm2cipher():
    window_sm2cipher_mode = {
        "C1C2C3": '0',
        "C1C3C2": '1'
    }

    def __init__(self, cipher_mode=None):
        self.ct = 1
        self.p2 = None
        self.sm3keybase = None
        self.sm3c3 = None
        # 长度为 32 的数组
        self.key = []
        self.keyOff = 0
        if not cipher_mode:
            self.cipher_mode = self.window_sm2cipher_mode.get("C1C3C2")
        else:
            self.cipher_mode = cipher_mode

    # def reset(self):
    #     self.sm3keybase = sm3Digest()
    #     self.sm3c3 = sm3Digest()
    #     x_words = self.byte_convert32_bytes(self.p2.getX())
    #     y_words = self.byte_convert32_bytes(self.p2.getY())

    def encrypt(self, pub_key, plaintext):
        data = []

    @classmethod
    def str2_bytes(cls, string):
        pos = 0
        length = len(string)
        if length % 2 != 0:
            return None
        hex_a = []
        while pos < length:
            b1 = int(string[pos], 16)
            b2 = int(string[pos + 1], 16)
            v = ((b1 << 4) | b2)
            hex_a.append(v)
            pos += 2
        return hex_a

    def create_point(self, pubkey_hex):

        KjurCryptoEcdsa({"curve": "sm2"})
